package apiday01.string;

public class StringDemo {
    public static void main(String[] args) {
        String s1 = "a123456a";
        String s2 = "a123456a";
        String s3 = "a123456a";
        String s4 = "a123";
        String s5 = new String("a123456a");
        System.out.println(s1==s2);//true，判断地址值是否相等
        System.out.println(s2==s3);//true
        System.out.println(s3==s4);//false
        System.out.println(s2==s5);//false
        System.out.println(s1.equals(s5));//true，判断字符串里的内容是否相等
        System.out.println("---------------------------------");

        String s = "a123";
        String s6 = s+ "456a";//字符串拼接
        String s7 = "a123" + "456a";//两字面量连接，触发预计算，直接编译为"a123456a"，复用对象
        System.out.println(s6==s1);//false,字符串拼接，创建新对象
        System.out.println(s7==s1);//true
        System.out.println("---------------------------------");

        String s8 = "a123a";
        String s9 = new String("a123a");
        System.out.println(s8==s9);//false
        System.out.println(s8.equals(s9));//true


    }
}
